<template>
  <div>
    <!--预览-->
    <div>
      <el-form ref="form" :inline="true" size="small">
        <monaco-editor-diff
          ref="monaco"
          :value="dataForm.sourceFileContent"
          :old-value="dataForm.convertFileContent"
          :language="language"
          style="height: 430px"
        />
      </el-form>
    </div>
  </div>
</template>
<script>
import scriptConvertListApi from '@/api/script/transfer/script-convert-list'
import scriptConvertTargetListApi from '@/api/script/transfer/script-convert-target-list'
import MonacoEditorDiff from '@/components/MonacoEditor/monacoEditorDiff'

export default {
  name: 'ScriptDetail',
  components: { MonacoEditorDiff },
  props: {
    crudPkId: {
      type: String
    },
    histPkId: {
      type: String
    },
    fileType: {
      type: String
    },
    convertFileName: {
      type: String
    }
  },
  data() {
    return {
      dataForm: { convertFileContent: null, sourceFileContent: null },
      language: 'python'
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      if (this.fileType === 'source') {
        scriptConvertListApi.queryContentById(this.crudPkId, this.histPkId).then(res => {
          this.dataForm = res
        })
      } else {
        scriptConvertTargetListApi.queryContentById(this.crudPkId, this.histPkId, this.convertFileName).then(res => {
          this.dataForm = res
        })
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.source {
  width: 400px;
  height: 550px;
  border: 1px solid #969494;
  overflow-x: hidden;

  p {
    background: #92dab3;
  }
}
</style>
